package com.wx.mall.operate.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wx.mall.common.api.CommonResult;
import com.wx.mall.operate.dto.DisSpuDto;
import com.wx.mall.operate.entity.DisSpu;
import com.wx.mall.operate.service.IDisSpuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 优惠券spu关联表 前端控制器
 * </p>
 *
 * @author j
 * @since 2020-05-13
 */
@RestController
@RequestMapping("/dis-spu")
@Api(tags = "优惠券和spu关联表",description = "DisSpuController")
@Slf4j
public class DisSpuController {

    @Resource
    private IDisSpuService spuService;

    @ApiOperation("添加数据")
    @PostMapping("/addList")
    public CommonResult addOne(DisSpuDto disSpuDto){
        System.out.println(disSpuDto);
         spuService.addOne(disSpuDto);
        return CommonResult.success();
    }

    @ApiOperation("清空数据根据优惠券id")
    @DeleteMapping("/deleteByDisId")
    public CommonResult deleteByDisId(Integer disId){
        System.out.println(disId);
        QueryWrapper<DisSpu> wrapper=new QueryWrapper<>();
        wrapper.eq("dis_id",disId);
        boolean suceess=spuService.remove(wrapper);

        return suceess?CommonResult.success():CommonResult.failed();
    }


}

